/**
 * Created by yangfan on 2016/10/25.
 */
define([
    'config/appregister',
    "i18n",
    "business/personMine/services/httpServices",
    "business/personMine/services/mineDirective",
    "business/services/personCenterComp",
    "business/services/detailNavComp",
    "business/services/filter"
    ],function(app,i18n,httpService){
    app.controller('myMainPageCtrl', function($scope,$state,$stateParams,$rootScope) {
        $scope.i18n = i18n;
        $scope.mycare = [
            {name:"116"},
            {name:"117"},
            {name:"118"},
            {name:"啥子归"},
            {name:"狮子"},
            {name:"老虎"},
            {name:"熊猫儿"},
        ];
        $scope.goToThePage = function(state){
            if(!state){
                return
            }
            $state.go(state);
        };
        $scope.listParams = {
            pageNo:1,
            pageSize:20,
            totalItem:"",
        };
        $scope.userPic = $rootScope.userLoginInfo.data.logo ;
        if( !angular.isUndefined($stateParams.userId)){
            $scope.userId = $stateParams.userId;
        }

        function getPersonDynamicList(){
            var req = {
                type:"GET",
                uri:"getPersonDynamicList",
                data:{
                    userId:$stateParams.userId,
                    pageNo:$scope.listParams.pageNo,
                    pageSize:$scope.listParams.pageSize
                }
            };
            httpService.myEngServices(req).success(function(response){
                $scope.$apply(function(){
                    console.log(response.data)
                    $scope.personList = response.data.list;
                    /*if($scope.listParams.pageNo ==1){
                        $scope.personList = response.data.list;
                    }else{
                        $scope.personList = $scope.personList.concat(response.data.list);
                    }*/
                    $scope.totalItem = response.data.Pagination.totalCount;
                    getListModel();
                });
            }).error(function(){

            })
        }
        function getFollowList(){
            var req = {
                type:"GET",
                uri:"getFollowList",
                //最多只查看6个
                data:{
                    pageNo:1,
                    pageSize:6
                }
            };
            httpService.followServices(req).success(function(response){
                $scope.$apply(function(){
                   $scope.follows = response.data.list;
                });
            }).error(function(){

            })
        }
        getPersonDynamicList();
        getFollowList();

        $scope.loadMoreComment = function(){
            $scope.listParams.pageNo++;
            getPersonDynamicList();
        }
		
		
		//获取我的问答
		function getPostbarById(){
			var req = {
                type:"GET",
                uri:"getPostbarById",
                data:{
                    pageNo:'1',
                    pageSize:'10',
                    all:'false'
                }
            };
            httpService.postbarServices(req).success(function(response){
                $scope.$apply(function(){
                    $scope.postbar = response.data.list;
                });
            }).error(function(){

            })
		}
		getPostbarById();
		
		//获取我的视频
		function getMyCourse(){
			var req = {
                type:"GET",
                uri:"getMyCourse",
                data:{
                    pageNo:'1',
                    pageSize:'10',
                    all:'false'
                }
            };
            httpService.videoServices(req).success(function(response){
                $scope.$apply(function(){
                    $scope.video = response.data.list;
                });
            }).error(function(){

            })
		}
		getMyCourse()

		//获取我的上传
		function myUploadFile(){
			var req = {
                type:"GET",
                uri:"myUploadFile",
                data:{
                    pageNo:'1',
                    pageSize:'10',
                    all:'false'
                }
            };
            httpService.fileServices(req).success(function(response){
                $scope.$apply(function(){
                    $scope.fileList = response.data.list;
                });
            }).error(function(){

            })
		}
        myUploadFile()
        function getListModel() {
            $scope.paginationConf = {
                currentPage: $scope.listParams.pageNo,
                totalItems: $scope.totalItem,
                //每页预览条数
                itemsPerPage: $scope.listParams.pageSize,
                //分页总数
                numberOfPages: Math.ceil($scope.totalItem / $scope.listParams.pageSize),
                // 实际分页长度
                pagesLength: 5,
                perPageOptions: [10, 20, 30, 40, 50],
                onChange: function(currentPage) {
                    if(currentPage) {
                        $scope.paginationConf.currentPage = currentPage;
                    }
                    $scope.list = [];
                    $scope.listParams.pageNo = $scope.paginationConf.currentPage;
                    getPersonDynamicList()
                }
            };
        }



		
		//更多  --  跳转
		$scope.goMore = function(ctrl){
			$state.go(ctrl)
		};
		
		//跳转详情
		$scope.goDetail = function(type,id){
			if(type == 'file'){
				$state.go('eng.techdetail',{fileId:id})
			}else if(type == 'course'){
				$state.go('eng.vedioDetails',{courseId:id})
			}else if(type == 'postbar'){
				$state.go('eng.postbardeta',{postbarId:id})
			}
		}
        $scope.jumpToPage = function(item){
            if(item.userType == 1){
                $state.go('othersMainPage',{userId:item.followUserId})
            }else{
                $state.go('outIndexCtrl',{companyId:item.followUserId})
            }

        }
    })
});
